/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.imgcog.image;

import java.awt.image.BufferedImage;
import technotheist.imgcog.util.ColUtil;

/**
 *
 * @author Mitch
 */
public class Image extends ImagePtr {

    private final float[] data;

    public Image(BufferedImage img, boolean color) {
        super(img.getWidth(), img.getHeight(), color ? 3 : 1);
        data = new float[width * height * pixSize];
        //
        int d = 0;
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int rgb = img.getRGB(x, y);
                if (color) {
                    data[d++] = ColUtil.getRed(rgb);
                    data[d++] = ColUtil.getGreen(rgb);
                    data[d++] = ColUtil.getBlue(rgb);
                } else {
                    data[d++] = ColUtil.getIntensity(rgb);
                }
            }
        }
    }
    
    public Image(float[] data, int w, int h, int col) {
        super(w, h, col);
        this.data = data;
    }

    @Override
    public float[] data() {
        return data;
    }
}
